//
//  PPContentTableViewCell.m
//  pet
//
//  Created by 陈无忌 on 12/6/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPContentTableViewCell.h"
#import "PPKeyWordsCollectionViewCell.h"

@interface PPContentTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@end

@implementation PPContentTableViewCell

- (void)awakeFromNib {
    // Initialization code
    self.keyWordCollectView.delegate = self;
    self.keyWordCollectView.dataSource = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)configCellWithReply:(NSString *)content
{
    self.contentLabel.text = content;
    self.contentLabel.frame = CGRectMake(10, 9, 300, 14);
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    [self.contentLabel sizeToFit];
    
    CGRect frame = self.contentLabel.frame;
    if (frame.size.height <= 18) {
        frame.origin.y = 19;
        self.contentLabel.frame = frame;
    }
    
    self.shareButton.frame = CGRectMake(246, [self getCellHeightWithReply:content] - 30 , 57, 25);
    self.keyWordCollectView.frame = CGRectMake(10, [self getCellHeightWithReply:content] - 30 , 222, 25);
    
    CGRect cellFrame = CGRectMake(0, 0, 320, [self getCellHeightWithReply:content]);
    self.BGIMG.frame = cellFrame;
    [self.keyWordCollectView reloadData];
}


+ (CGFloat)getCellHeightWithReply:(NSString *)content{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, 300, 12)];
    label.font = [UIFont systemFontOfSize:14.0];
    label.text = content;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByCharWrapping;
    [label sizeToFit];
    if (label.frame.size.height > 32) {
        return 9 + label.frame.size.height + 4 + 9 + 5 + 25 +5;
    }else{
        return 55 + 30;
    }
}

- (CGFloat)getCellHeightWithReply:(NSString *)content
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, 300, 12)];
    label.font = [UIFont systemFontOfSize:14.0];
    label.text = content;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByCharWrapping;
    [label sizeToFit];
    if (label.frame.size.height > 32) {
        return 9 + label.frame.size.height + 4 + 9 + 5 + 25 +5;
    }else{
        return 55 + 30;
    }
}

- (NSArray *)getKeyWordWithKeywordString:(NSString *)string
{
    return [string componentsSeparatedByString:@" "];
}

#pragma mark - UICollection view datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.keywordList.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *string = [self.keywordList objectAtIndex:indexPath.row];
    PPKeyWordsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"keywordCell" forIndexPath:indexPath];
    [cell.keywordButton setTitle:string forState:UIControlStateNormal];
    return cell;
}


@end
